package com.itheima.array;

import java.util.Scanner;

/*
    改变数组
  */
public class WorkArray01 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //1.建立动态初始化数组
        int[] arr = new int[10];
        //开始键盘录入
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个数:");
            arr[i] = sc.nextInt();
        }
        print(arr);
        arr = change(arr);
        print(arr);
        print1(arr);
    }

    //2.处理数组
    public static int[] change(int[] arr) {
        int[] change = new int[arr.length];
        int j = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 1) {
                change[j] = arr[i];
                j++;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 0) {
                change[j] = arr[i];
                j++;
            }
        }
        return change;
    }

    //3.打印变化前后
    public static void print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println("");
    }

    //4.输出单一出现的数字几个数
    public static void print1(int[] arr) {
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if (arr[i] == arr[j] && i != j) {
                    break;
                } else {
                    if (j == arr.length - 1) {
                        System.out.println(arr[i]);
                        count++;
                    }
                    continue;
                }
            }
        }
        System.out.println("单一出现的个数为:" + count);
    }
}
